<!--
  功能说明：登录页面，演示调用认证 API 并更新全局状态。
-->
<template>
  <div>
    <h2>用户登录</h2>
    <form @submit.prevent="onSubmit">
      <div>
        <label>用户名：</label>
        <input v-model="username" placeholder="请输入用户名" />
      </div>
      <div>
        <label>密码：</label>
        <input type="password" v-model="password" placeholder="请输入密码" />
      </div>
      <button type="submit">登录</button>
    </form>
  </div>
</template>

<script>
export default {
  name: 'LoginPage',
  data() {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit() {
      try {
        await this.$store.dispatch('auth/login', { username: this.username, password: this.password })
        this.$router.push('/users')
      } catch (e) {
        // 错误已由全局错误模块记录，这里保留最简处理
      }
    }
  }
}
</script>